//
//  BYBaseTabBarViewController.m
//  BYControls
//
//  Created by 彬boy on 2018/11/14.
//  Copyright © 2018年 彬boy. All rights reserved.
//

#import "BYBaseTabBarViewController.h"
#import "BYBaseNavViewController.h"

#define kClassKey @"rootVCClassString"
#define kTitleKey @"title"
#define kImgKey   @"imageName"
#define kSelImgKey @"selectImageName"
#define kThemeColor [UIColor colorWithRed:240 green:(140 / 255.0) blue:(66 / 255.0) alpha:1]

@interface BYBaseTabBarViewController ()

@end

@implementation BYBaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *childItemsArray = @[
                                 @{kClassKey : @"BYHomeViewController",
                                   kTitleKey : @"1",
                                   kImgKey   : @"tabbar_home",
                                   kSelImgKey: @"tabbar_home_highlighted"},
                                 @{kClassKey : @"BYVideoViewController",
                                   kTitleKey : @"2",
                                   kImgKey   : @"tabbar_home",
                                   kSelImgKey: @"tabbar_home_highlighted"},
                                 @{kClassKey : @"BYMiddleViewController.h",
                                   kTitleKey : @"3",
                                   kImgKey   : @"tabbar_home",
                                   kSelImgKey: @"tabbar_home_highlighted"},
                                 @{kClassKey : @"BYCommunityViewController",
                                   kTitleKey : @"4",
                                   kImgKey   : @"tabbar_home",
                                   kSelImgKey: @"tabbar_home_highlighted"},
                                 @{kClassKey : @"BYMineViewController",
                                   kTitleKey : @"5",
                                   kImgKey   : @"tabbar_home",
                                   kSelImgKey: @"tabbar_home_highlighted"}
                                 ];
    [childItemsArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIViewController *vc = [NSClassFromString(obj[kClassKey]) new];
        vc.title = obj[kTitleKey];
        BYBaseNavViewController *nav = [[BYBaseNavViewController alloc] initWithRootViewController:vc];
        [nav zj_enableFullScreenPop:YES];
        UITabBarItem *item = nav.tabBarItem;
        item.title = obj[kTitleKey];
        item.image = [UIImage imageNamed:obj[kImgKey]];
        item.selectedImage = [[UIImage imageNamed:obj[kSelImgKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : kThemeColor} forState:UIControlStateSelected];
        [self addChildViewController:nav];
    }];
}

@end
